package com.example;

import com.alibaba.fastjson.JSON;
import com.example.constant.CommonConstant;
import com.example.pojo.MySQLConfig;
import org.I0Itec.zkclient.ZkClient;

/**
 * @author HuangMin
 */
public class ZkChangeNode {

    public static void main(String[] args) {
        MySQLConfig mySQLConfig = new MySQLConfig();
        mySQLConfig.setDriver(CommonConstant.driver);
        mySQLConfig.setUrl(CommonConstant.springbootdataUrl);
        mySQLConfig.setUsername(CommonConstant.username);
        mySQLConfig.setPassword(CommonConstant.password);
        ZkClient zkClient = new ZkClient("127.0.0.1:2181", 3000);
        if (zkClient.exists(CommonConstant.rootPath)) {
            zkClient.writeData(CommonConstant.rootPath, JSON.toJSONString(mySQLConfig));
        }else{
            zkClient.createPersistent(CommonConstant.rootPath, JSON.toJSONString(mySQLConfig));
        }
    }
}
